package algorithm.sort;

public class Bubble {
    public void bubbleSort(Comparable[] arr) {
        int n =arr.length;
        for (int i = n-1;i >0;i--) {
            for(int j =0;j<i;j++) {
                if (greater(arr[j],arr[j+1])) {
                    swap(arr,j,j+1);
                }
            }
        }
    }

    public Boolean greater(Comparable a, Comparable b){
        return a.compareTo(b)>0;
    }

    public void swap(Comparable[] arr, int i ,int j) {
        Comparable tmp = arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }
}
